<?php
class RSS_Model extends CI_Model 
{
    function __construct()
    {
        parent::__construct();
    }
	
	function get_products_using_category_id($category_id=0, $start=0, $limit=10)
	{
	
		$query = "SELECT slug_product_title, product_id, product_title, rss_publish_date, post_date, product_desc, product_count FROM products INNER JOIN categories on categories.category_id=products.category_id WHERE products.rss_generated_on < categories.rss_generated_on AND categories.category_id=$category_id order by products.rss_generated_on asc limit $start, $limit";
		$products = $this->db->query($query);
		$product_ids = array();
		$row = null;
		$product_count = 0;
		foreach ($products->result() as $row)
		{
			$product_ids[] = $row->product_id;
			$product_count = $row->product_count;
		}
		
		if($product_count > $limit && count($product_ids) > 0)
		{
			$this->db->query('update products set rss_generated_on = now() where product_id in ('.implode (',', $product_ids).')');
			$this->db->query('update categories set rss_generated_on = now() where category_id ='.$category_id);
			
		}
		// echo implode (',', $product_ids); exit;
		return $products;
	}
	
	function get_recent_products($start=0, $limit=10)
	{
		$query = " SELECT product_id, product_title"
				." , product_content as description "
				." , '" . $this->config->config['base_url'] . "' as link"
				." , product_title as slug_title "
				." FROM products "
				." LIMIT $start, $limit";
		
		return $this->db->query($query);
	}
	
	
}

/* End of file RSS_Model */
/* Location: ./application/model/RSS_Model.php */